<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class Cms_Match extends Model
{
    use HasFactory;

    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'cms_match';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    protected $fillable = [
        'mid',
        'otherid',
        'maker_id',
        'meet_time',
        'create_time',
        'update_time',
        'is_del'
    ];
    public function scopeNodel($query)
    {
        return $query->where('is_del', 0);
    }

    protected $hidden = [
        'is_del',
    ];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function hasOneMember()
    {
        return $this->hasOne('App\Models\Cms_Member', 'id', 'mid');
    }

    public function hasOneOtherMember()
    {
        return $this->hasOne('App\Models\Cms_Member', 'id', 'otherid');
    }

    public function hasOneUser()
    {
        return $this->hasOne('App\Models\Sys_User', 'id', 'maker_id');
    }

    public static function getFilter($filter)
    {
        return self::where(function ($query) use ($filter){
            if (isset($filter['mid']) && !empty($filter['mid'])) {
                $query->where('mid',  $filter['mid'] );
            }
        });
    }
}
